|
|
|
|
|
|
|
Figure 1.27
Example program ImagePic demonstrates the Picture and Image properties. |
|
|
|
|
|
|
|
|
A form's Icon property contains the icon that is displayed when the form is minimized. Usually you set a form's icon by selecting a .ico file at design time or by loading an icon using the LoadPicture function. |
|
|
|
|
|
|
|
|
The LoadPicture and SavePicture Functions |
|
|
|
|
|
|
|
|
As you might guess from their names, LoadPicture and SavePicture load and save pictures to and from files. You can use LoadPicture to load a picture into a form, picture box, or image control, as in: |
|
|
|
 |
|
|
|
|
picSmile.Picture = LoadPicture("grin.bmp") |
|
|
|
|
|
|
|
|
In older versions of Visual Basic, LoadPicture could load images stored in the file formats bitmap (.bmp), device-independent bitmap (.dib), icon (.ico), run-length encoded (.rle), or Windows metafile with placeable header (.wmf). Newer versions of Visual Basic can also read images stored in Graphics Interchange Format (.gif) and Joint Photographic Electronic Group (.jpeg or .jpg) formats. |
|
|
|
|
|
|
|
|
You can use SavePicture to save the contents of a form, picture box, or image control to a file, as shown in the following code: |
|
|
|
 |
|
|
|
|
SavePicture Pict.Image, "MYPICT.BMP" |
|
|
|
|
|
|
|
|
When you load an image at design time, it is stored in the form's data in its original format. When it is displayed at run time, it is converted into an appropriate format for display. For example, if you load a compressed JPEG file onto a form, the form stores the compressed data. That makes the program smaller than it would have been had you loaded the image from a bitmap. On the other hand, the program will take longer to display the image because it must decompress it at run time. |
|
|
|
|
|